In computing, a vector processor is a central processing unit (CPU) that implements an instruction set where its instructions are designed to operate efficiently and architecturally sequentially on large one-dimensional arrays of data called vectors. When integrated as a hardware component the vector processor is often called a vector processing unit (VPU). This is in contrast to , whose instructions operate on single data items only, and in contrast to some of those same scalar processors having additional single instruction, multiple data (SIMD) or SIMD within a register (SWAR) Arithmetic Units. Vector processors can greatly improve performance on certain workloads, notably numerical simulation, Data compression and similar tasks.
Vector processing techniques also operate in video-game console hardware and in graphics accelerators but these are invariably Single instruction, multiple threads (SIMT) and occasionally Single instruction, multiple data (SIMD).
Vector machines appeared in the early 1970s and dominated supercomputer design through the 1970s into the 1990s, notably the various Cray platforms. The rapid fall in the price-to-performance ratio of conventional microprocessor designs led to a decline in vector supercomputers during the 1990s.
In 1962, Westinghouse cancelled the project, but the effort was restarted by the University of Illinois at Urbana–Champaign as the ILLIAC IV. Their version of the design originally called for a 1 GFLOPS machine with 256 ALUs, but, when it was finally delivered in 1972, it had only 64 ALUs and could reach only 100 to 150 MFLOPS. Nevertheless, it showed that the basic concept was sound, and, when used on data-intensive applications, such as computational fluid dynamics, the ILLIAC was the fastest machine in the world. The ILLIAC approach of using separate ALUs for each data element is not common to later designs, and is often referred to under a separate category of massively parallel computing: around 1972 Flynn categorized this type of processing as an early form of single instruction, multiple threads (SIMT).
International Computers Limited sought to avoid many of the difficulties with the ILLIAC concept with its own Distributed Array Processor (DAP) design, categorising the ILLIAC and DAP as cellular array processors that potentially offered substantial performance benefits over conventional vector processor designs such as the CDC STAR-100 and Cray 1.
The basic ASC (i.e., "one pipe") ALU used a pipeline architecture that supported both scalar and vector computations, with peak performance reaching approximately 20 MFLOPS, readily achieved when processing long vectors. Expanded ALU configurations supported "two pipes" or "four pipes" with a corresponding 2X or 4X performance gain. Memory bandwidth was sufficient to support these expanded modes.
The STAR-100 was otherwise slower than CDC's own supercomputers like the CDC 7600, but at data-related tasks they could keep up while being much smaller and less expensive. However the machine also took considerable time decoding the vector instructions and getting ready to run the process, so it required very specific data sets to work on before it actually sped anything up.
The vector technique was first fully exploited in 1976 by the famous Cray-1. Instead of leaving the data in memory like the STAR-100 and ASC, the Cray design had eight vector registers, which held sixty-four 64-bit words each. The vector instructions were applied between registers, which is much faster than talking to main memory. Whereas the STAR-100 would apply a single operation across a long vector in memory and then move on to the next operation, the Cray design would load a smaller section of the vector into registers and then apply as many operations as it could to that data, thereby avoiding many of the much slower memory access operations.
The Cray design used pipeline parallelism to implement vector instructions rather than multiple ALUs. In addition, the design had completely separate pipelines for different instructions, for example, addition/subtraction was implemented in different hardware than multiplication. This allowed a batch of vector instructions to be pipelined into each of the ALU subunits, a technique they called vector chaining. The Cray-1 normally had a performance of about 80 MFLOPS, but with up to three chains running it could peak at 240 MFLOPS and averaged around 150 – far faster than any machine of the era.
Other examples followed. Control Data Corporation tried to re-enter the high-end market again with its ETA-10 machine, but it sold poorly and they took that as an opportunity to leave the supercomputing field entirely. In the early and mid-1980s Japanese companies Fujitsu, Hitachi and NEC introduced register-based vector machines similar to the Cray-1, typically being slightly faster and much smaller: the Fujitsu VP series culminated in the VP2600 holding the world record fastest supercomputer in 1990-1991. Oregon-based Floating Point Systems (FPS) built add-on array processors for , later building their own minisupercomputers.
Throughout, Cray continued to be the performance leader, continually beating the competition with a series of machines that led to the Cray-2, Cray X-MP and Cray Y-MP. Since then, the supercomputer market has focused much more on massively parallel processing rather than better implementations of vector processors. However, recognising the benefits of vector processing, IBM developed Virtual Vector Architecture for use in supercomputers coupling several scalar processors to act as a vector processor. IBM also implemented Cray-style Vector processing in the IBM 3090 with an optional vector facility.
Although vector supercomputers resembling the Cray-1 are less popular these days, NEC has continued to make this type of computer up to the present day with their SX series of computers. Most recently, the SX-Aurora TSUBASA places the processor and either 24 or 48 gigabytes of memory on an HBM 2 module within a card that physically resembles a graphics coprocessor, but instead of serving as a co-processor, it is the main computer with the PC-compatible computer into which it is plugged serving support functions.
most commodity CPUs implement architectures that feature fixed-length SIMD instructions. On first inspection these can be considered a form of vector processing because they operate on multiple (vectorized, explicit length) data sets, and borrow features from vector processors. However, by definition, the addition of SIMD cannot, by itself, qualify a processor as an actual ''vector processor'', because SIMD is , and vectors are . The difference is illustrated below with examples, showing and comparing the three categories: pure SIMD, predicated SIMD, and pure vector processing.
Other CPU designs include some multiple instructions for vector processing on multiple (vectorized) data sets, typically known as MIMD (multiple instruction, multiple data) and realized with VLIW (very long instruction word) and EPIC (explicitly parallel instruction computing). The Fujitsu FR-V, for example, combines VLIW features with predication and packed SIMD.*
Pure (fixed-width, no predication) SIMD is often mistakenly claimed to be "vector" (because SIMD processes data which happens to be vectors). Close analysis and comparison of historic and modern ISAs shows actual vector ISAs to have a way to set the vector length at runtime, and to a non-power-of-two quantity. In other words, the number of elements is not hard-encoded in the instruction as it is in SIMD ISA. This is explained in the "SIMD Considered harmful" article.
An additional key feature is element-level predicated masking. In the Cyber 200 Model the element-level bitmask was itself a Vector stored in memory. Some Vector processors have Vector mask registers as exemplified by the Cray-1 which, like the Cyber 200, efficiently used one bit per element as a mask. However other Vector ISAs such as RISC-V elected to use a register from the main Vector register file.
Predicated SIMD (part of Flynn's taxonomy) is comprehensive individual element-level predicate masks on every element, as is now available in ARM SVE2 and AVX-512, but neither of these Instruction sets has an actual explicit "set vector length" instruction. Predicated SIMD uses fixed-width SIMD ALUs but allows locally controlled (predicated) activation of units to provide the appearance of variable length vectors. Examples below help explain these categorical distinctions.
Another key difference: SIMD, because it uses fixed-width batch processing, is to cope with iteration and reduction. This is illustrated further with examples, below.
To reduce the amount of time consumed by these steps, most modern CPUs use a technique known as instruction pipelining in which the instructions pass through several sub-units in turn. The first sub-unit reads the address and decodes it, the next "fetches" the values at those addresses, and the next does the math itself. With pipelining the "trick" is to start decoding the next instruction even before the first has left the CPU, in the fashion of an assembly line, so the address decoder is constantly in use. Any particular instruction takes the same amount of time to complete, a time known as the latency, but the CPU can process an entire batch of operations, in an overlapping fashion, much faster and more efficiently than if it did so one at a time.
Vector processors take this concept one step further. Instead of pipelining just the instructions, they also pipeline the data itself. The processor is fed instructions that say not just to add A to B, but to add all of the numbers "from here to here" to all of the numbers "from there to there". Instead of constantly having to decode instructions and then fetch the data needed to complete them, the processor reads a single instruction from memory, and it is simply implied in the definition of the instruction itself that the instruction will operate again on another item of data, at an address one increment larger than the last. This significantly maximises instruction effectiveness.
To illustrate what a difference this can make, consider the simple task of adding two groups of 10 numbers together. In a normal programming language one would write a "loop" that picked up each of the pairs of numbers in turn, and then added them. To the CPU, this would look something like this:
move $10, count ; count := 10
loop:
load r1, a
load r2, b
add r3, r1, r2 ; r3 := r1 + r2
store r3, c
add a, a, $4 ; move on
add b, b, $4
add c, c, $4
dec count ; decrement
jnez count, loop ; loop back if count is not yet 0
ret
But to a vector processor, this task looks considerably different:
move $10, count ; count = 10
vload v1, a, count
vload v2, b, count
vadd v3, v1, v2
vstore v3, c, count
ret
Note the complete lack of looping in the instructions, because it is the hardware which has performed 10 sequential operations: effectively the loop count is on an explicit per-instruction basis.
Cray-style vector ISAs take this a step further and provide a global "count" register, called vector length (VL):
setvli $10 # Set vector length VL=10
vload v1, a # 10 loads from a
vload v2, b # 10 loads from b
vadd v3, v1, v2 # 10 adds
vstore v3, c # 10 stores into c
ret
There are several savings inherent in this approach.
Additionally, in more modern vector processor ISAs, "Fail on First" or "Fault First" has been introduced (see below) which brings even more advantages.
But more than that, a high performance vector processor may have multiple adding those numbers in parallel. The checking of dependencies between those numbers is not required as a vector instruction specifies multiple independent operations. This simplifies the control logic required, and can further improve performance by avoiding stalls. The math operations thus completed far faster overall, the limiting factor being the time required to fetch the data from memory.
Not all problems can be attacked with this sort of solution. Including these types of instructions necessarily adds complexity to the core CPU. That complexity typically makes other instructions run slower—i.e., whenever it is not adding up many numbers in a row. The more complex instructions also add to the complexity of the decoders, which might slow down the decoding of the more common instructions such as normal adding. ( This can be somewhat mitigated by keeping the entire ISA to RISC principles: RVV only adds around 190 vector instructions even with the advanced features.)
Vector processors were traditionally designed to work best only when there are large amounts of data to be worked on. For this reason, these sorts of CPUs were found primarily in , as the supercomputers themselves were, in general, found in places such as weather prediction centers and physics labs, where huge amounts of data are "crunched". However, as shown above the efficiency of vector ISAs brings other benefits which are compelling even for Embedded use-cases.
The self-repeating instructions are found in early vector computers like the STAR-100, where the above action would be described in a single instruction (somewhat like ). They are also found in the x86 architecture as the prefix. However, only very simple calculations can be done effectively in hardware this way without a very large cost increase. Since all operands have to be in memory for the STAR-100 architecture, the latency caused by access became huge too.
Broadcom included space in all vector operations of the Videocore IV ISA for a field, but unlike the STAR-100 which uses memory for its repeats, the Videocore IV repeats are on all operations including arithmetic vector operations. The repeat length can be a small range of power of two or sourced from one of the scalar registers. Videocore IV Programmer's Manual
The Cray-1 introduced the idea of using processor registers to hold vector data in batches. The batch lengths (vector length, VL) could be dynamically set with a special instruction, the significance compared to Videocore IV (and, crucially as will be shown below, SIMD as well) being that the repeat length does not have to be part of the instruction encoding. This way, significantly more work can be done in each batch; the instruction encoding is much more elegant and compact as well. The only drawback is that in order to take full advantage of this extra batch processing capacity, the memory load and store speed correspondingly had to increase as well. This is sometimes claimed to be a disadvantage of Cray-style vector processors, and the Fujitsu VP series did make this mistake: in reality it is part of achieving high performance throughput, as seen in , which face exactly the same issue.
Modern SIMD computers claim to improve on early Cray by directly using multiple ALUs, for a higher degree of parallelism compared to only using the normal scalar pipeline. Modern vector processors (such as the SX-Aurora TSUBASA) combine both, by issuing multiple data to multiple internal pipelined SIMD ALUs, the number issued being dynamically chosen by the vector program at runtime. Masks can be used to selectively load and store data in memory locations, and use those same masks to selectively disable processing element of SIMD ALUs. Some processors with SIMD (AVX-512, ARM SVE2) are capable of this kind of selective, per-element ("predicated") processing, and it is these which somewhat deserve the nomenclature "vector processor" or at least deserve the claim of being capable of "vector processing". SIMD processors without per-element predication (MMX, SSE, AltiVec) categorically do not.
Modern GPUs, which have many small compute units each with their own independent SIMD ALUs, use Single Instruction Multiple Threads (SIMT). SIMT units run from a shared single broadcast synchronised Instruction Unit. The "vector registers" are very wide and the pipelines tend to be long. The "threading" part of SIMT involves the way data is handled independently on each of the compute units.
In addition, GPUs such as the Broadcom Videocore IV and other external vector processors like the NEC SX-Aurora TSUBASA may use fewer vector units than the width implies: instead of having 64 units for a 64-number-wide register, the hardware might instead do a pipelined loop over 16 units for a hybrid approach. The Broadcom Videocore IV is also capable of this hybrid approach: nominally stating that its SIMD QPU Engine supports 16-long FP array operations in its instructions, it actually does them 4 at a time, as (another) form of "threads". Videocore IV QPU analysis by Jeff Bush
for (size_t i = 0; i < n; i++) {
y[i] = a * x[i] + y[i];
}
}
In each iteration, every element of y has an element of x multiplied by a and added to it. The program is expressed in scalar linear form for readability.
load32 r1, x ; load one 32bit data
load32 r2, y
mul32 r1, a, r1 ; r1 := r1 * a
add32 r3, r1, r2 ; r3 := r1 + r2
store32 r3, y
addl x, x, $4 ; x := x + 4
addl y, y, $4
subl n, n, $1 ; n := n - 1
jgz n, loop ; loop back if n > 0
out:
ret
The STAR-like code remains concise, but because the STAR-100's vectorisation was by design based around memory accesses, an extra slot of memory is now required to process the information. Two times the latency is also needed due to the extra requirement of memory access.
; Assume tmp is pre-allocated
vmul tmp, a, x, n ; tmp[i] = a * x[i]
vadd y, y, tmp, n ; y[i] = y[i] + tmp[i]
ret
splatx4 v4, a ; v4 = a,a,a,a
The time taken would be basically the same as a vector implementation of described above.
load32x4 v1, x
load32x4 v2, y
mul32x4 v1, a, v1 ; v1 := v1 * a
add32x4 v3, v1, v2 ; v3 := v1 + v2
store32x4 v3, y
addl x, x, $16 ; x := x + 16
addl y, y, $16
subl n, n, $4 ; n := n - 4
jgz n, vloop ; go back if n > 0
out:
ret
Note that both x and y pointers are incremented by 16, because that is how long (in bytes) four 32-bit integers are. The decision was made that the algorithm shall only cope with 4-wide SIMD, therefore the constant is hard-coded into the program.
Unfortunately for SIMD, the clue was in the assumption above, "that n is a multiple of 4" as well as "aligned access", which, clearly, is a limited specialist use-case.
Realistically, for general-purpose loops such as in portable libraries, where n cannot be limited in this way, the overhead of setup and cleanup for SIMD in order to cope with non-multiples of the SIMD width, can far exceed the instruction count inside the loop itself. Assuming worst-case that the hardware cannot do misaligned SIMD memory accesses, a real-world algorithm will:
This more than triples the size of the code, in fact in extreme cases it results in an order of magnitude increase in instruction count! This can easily be demonstrated by compiling the iaxpy example for AVX-512, using the options to gcc.
Over time as the ISA evolves to keep increasing performance, it results in ISA Architects adding 2-wide SIMD, then 4-wide SIMD, then 8-wide and upwards. It can therefore be seen why AVX-512 exists in x86.
Without predication, the wider the SIMD width the worse the problems get, leading to massive opcode proliferation, degraded performance, extra power consumption and unnecessary software complexity. SIMD considered harmful
Vector processors on the other hand are designed to issue computations of variable length for an arbitrary count, n, and thus require very little setup, and no cleanup. Even compared to those SIMD ISAs which have masks (but no instruction), Vector processors produce much more compact code because they do not need to perform explicit mask calculation to cover the last few elements (illustrated below).
# prepare mask. few ISAs have min though
min t0, n, $4 ; t0 = min(n, 4)
shift m, $1, t0 ; m = 1<
out:
ret
Here it can be seen that the code is much cleaner but a little complex: at least, however, there is no setup or cleanup: on the last iteration of the loop, the predicate mask will be set to either 0b0000, 0b0001, 0b0011, 0b0111 or 0b1111, resulting in between 0 and 4 SIMD element operations being performed, respectively. One additional potential complication: some RISC ISAs do not have a "min" instruction, needing instead to use a branch or scalar predicated compare.
It is clear how predicated SIMD at least merits the term "vector capable", because it can cope with variable-length vectors by using predicate masks. The final evolving step to a "true" vector ISA, however, is to not have any evidence in the ISA at all of a SIMD width, leaving that entirely up to the hardware.
On calling with the number of outstanding data elements to be processed, "" is permitted (essentially required) to limit that to the Maximum Vector Length (MVL) and thus returns the actual number that can be processed by the hardware in subsequent vector instructions, and sets the internal special register, "VL", to that same amount. ARM refers to this technique as "vector length agnostic" programming in its tutorials on SVE2. ARM SVE2 tutorial
Below is the Cray-style vector assembler for the same SIMD style loop, above. Note that t0 (which, containing a convenient copy of VL, can vary) is used instead of hard-coded constants:
setvl t0, n # VL=t0=min(MVL, n)
vld32 v0, x # load vector x
vld32 v1, y # load vector y
vmadd32 v1, v0, a # v1 += v0 * a
vst32 v1, y # store Y
add y, t0*4 # advance y by VL*4
add x, t0*4 # advance x by VL*4
sub n, t0 # n -= VL (t0)
bnez n, vloop # repeat if n != 0
This is essentially not very different from the SIMD version (processes 4 data elements per loop if MVL is 4), or from the initial Scalar version (processes just the one). n still contains the number of data elements remaining to be processed, but t0 contains the copy of VL – the number that is going to be processed in each iteration. t0 is subtracted from n after each iteration, and if n is zero then all elements have been processed.
A number of things to note, when comparing against the Predicated SIMD assembly variant:
Thus it can be seen, very clearly, how vector ISAs reduce the number of instructions.
Also note, that just like the predicated SIMD variant, the pointers to x and y are advanced by t0 times four because they both point to 32 bit data, but that n is decremented by straight t0. Compared to the fixed-size SIMD assembler there is very little apparent difference: x and y are advanced by hard-coded constant 16, n is decremented by a hard-coded 4, so initially it is hard to appreciate the significance. The difference comes in the realisation that the vector hardware could be capable of doing 4 simultaneous operations, or 64, or 10,000, it would be the exact same vector assembler for all of them and there would still be no SIMD cleanup code. Even compared to the predicate-capable SIMD, it is still more compact, clearer, more elegant and uses less resources.
Not only is it a much more compact program (saving on L1 Cache size), but as previously mentioned, the vector version can issue far more data processing to the ALUs, again saving power because Instruction Decode and Issue can sit idle.
Additionally, the number of elements going in to the function can start at zero. This sets the vector length to zero, which effectively disables all vector instructions, turning them into , at runtime. Thus, unlike non-predicated SIMD, even when there are no elements to process there is still no wasted cleanup code, or preamble: not even when n=0.
VLVCU GR4 # Load VCT, update GR4 & CCode
vloop:
vld32 v0, x, v0 # load vector x, update v0
vld32 v1, y # load vector y (no update v1)
vmadd32 v1, v0, a # v1 += v0 * a
vst32 v1, y, v1 # store Y, now update v1
VLVCU GR4 # Load VCT, update GR4 & CCode
BC 3,vloop # Branch back if VCT>0
The instruction would not only set the Vector Count Length () but it would then subtract the new Vector Length from the Scalar register and update a Condition Code that the Branch could test. In effect combined two (three if including Condition Code setting) into one:
# IBM 370 VLVCU does the following:
setvl GR4 # VL=min(MVL, GR4)
sub GR4, VL # n -= VL (GR4), also set CC
Further, both the Vector-Load and Vector-Store instructions could perform the update of the address registers, saving on explicit instructions to perform address-calculations that in effect had already been done, behind the scenes, when loading/storing each element of the Vector.
The exact same principle is used in Libre-SOC, illustrated with a DAXPY (64-bit floating-point) example:
mtctr 5 # move n to CTR
vloop:
setvl MAXVL=32,VL=CTR # actually VL=MIN(MAXVL,CTR)
# DAXPY is 8-byte, hence 8(r6) and 8(r7)
sv.lfdup *32,8(r6) # load x into fp32-63, incr x
sv.lfd/els *64,8(r7) # load y into fp64-95, NO INC
sv.fmadd *64,*64,1,*32 # (*y) = (*y) * (*x) + a
sv.stfdup *64,8(r7) # store at y, post-incr y
sv.bc/ctr vloop # decr CTR by VL, jump !zero
Post-update modes are added to Vectorised versions of Load-with-Update and Store-with-Update, again saving on the need for a separate instruction for address computation when the CPU's Load/Store internals has already done it. Note again that as with the IBM 370 example: the Vector y address is updated by the Store-with-Update, not a Load-with-Update. The Power ISA CTR register is used for the total count instead of a scalar register, and the instruction performs the reduction of CTR by the current Vector Length (VL) followed by testing CTR for being zero and branching if it is not.
The approach is different but achieves the same end-result as the IBM 3090: a significant compacting of instructions that are already considered highly compact. a RISC-V Vector DAXPY inner loop example is 10 instructions, where Libre-SOC and IBM 370 as shown above are both 6: a 40% reduction.
int y = 0;
for (size_t i = 0; i < n; i++)
y += x[i];
return y;
}
Here, an accumulator (y) is used to sum up all the values in the array, x.
set y, 0 ; y initialised to zero
loop:
load32 r1, x ; load one 32bit data
add32 y, y, r1 ; y := y + r1
addl x, x, $4 ; x := x + 4
subl n, n, $1 ; n := n - 1
jgz n, loop ; loop back if n > 0
out:
ret y ; returns result, y
This is very straightforward. "y" starts at zero, 32 bit integers are loaded one at a time into r1, added to y, and the address of the array "x" moved on to the next element in the array.
addl r3, x, $16 ; for 2nd 4 of x
load32x4 v1, x ; first 4 of x
load32x4 v2, r3 ; 2nd 4 of x
add32x4 v1, v2, v1 ; add 2 groups
At this point four adds have been performed:
Even with a general loop (n not fixed), the only way to use 4-wide SIMD is to assume four separate "streams", each offset by four elements. Finally, the four partial results have to be summed. The problems compound as the SIMD hardware width increases (an entirely new set of instruction is introduced), and, worse, some instructions to do Horizontal-sum such as the AMD XOP_instruction_set, were removed after a few years. Some techniques involve shuffle: examples online that involve highly detailed knowledge can be found for AVX-512 and SSE of how to do "Horizontal Sum"
Aside from the size of the program and the complexity, an additional potential problem arises if floating-point computation is involved: the fact that the values are not being summed in strict order (four partial results) could result in rounding errors.
setvl t0, n # VL=t0=min(MVL, n)
vld32 v0, x # load vector x
vredadd32 y, v0 # reduce-add into y
The code when n is larger than the maximum vector length is not that much more complex, and is a similar pattern to the first example ("IAXPY").
set y, 0
vloop:
setvl t0, n # VL=t0=min(MVL, n)
vld32 v0, x # load vector x
vredadd32 y, y, v0 # add all x into y
add x, t0*4 # advance x by VL*4
sub n, t0 # n -= VL (t0)
bnez n, vloop # repeat if n != 0
ret y
The simplicity of the algorithm is stark in comparison to SIMD. Again, just as with the IAXPY example, the algorithm is length-agnostic (even on Embedded implementations where maximum vector length could be only one).
Implementations in hardware may, if they are certain that the right answer will be produced, perform the reduction in parallel. Some vector ISAs offer a parallel reduction mode as an explicit option, for when the programmer knows that any potential rounding errors do not matter, and low latency is critical.
This example again highlights a key critical fundamental difference between true vector processors and those SIMD processors, including most commercial GPUs, which are inspired by features of vector processors.
Overall then there is a choice to either have
These stark differences are what distinguishes a vector processor from one that has SIMD.
The basic principle of is to attempt a large sequential vector load, but to allow the hardware to arbitrarily truncate the actual amount loaded to either the amount that would succeed without raising a memory fault or simply to an amount (greater than zero) that is most convenient. The important factor is that subsequent instructions are notified or may determine exactly how many loads actually succeeded, using that quantity to only carry out work on the data that has actually been loaded.
Contrast this situation with SIMD, which is a fixed (inflexible) load width and fixed data processing width, unable to cope with loads that cross page boundaries, and even if they were they are unable to adapt to what actually succeeded, yet, paradoxically, if the SIMD program were to even attempt to find out in advance (in each inner loop, every time) what might optimally succeed, those instructions only serve to hinder performance because they would, by necessity, be part of the critical inner loop.
This begins to hint at the reason why is so innovative, and is best illustrated by memcpy or strcpy when implemented with standard 128-bit non-predicated SIMD. For IBM POWER9 the number of hand-optimised instructions to implement strncpy is in excess of 240. PATCH to libc6 to add optimised POWER9 strncpy By contrast, the same strncpy routine in hand-optimised RVV assembler is a mere 22 instructions. RVV strncpy example
The above SIMD example could potentially fault and fail at the end of memory, due to attempts to read too many values: it could also cause significant numbers of page or misaligned faults by similarly crossing over boundaries. In contrast, by allowing the vector architecture the freedom to decide how many elements to load, the first part of a strncpy, if beginning initially on a sub-optimal memory boundary, may return just enough loads such that on subsequent iterations of the loop the batches of vectorised memory reads are optimally aligned with the underlying caches and virtual memory arrangements. Additionally, the hardware may choose to use the opportunity to end any given loop iteration's memory reads exactly on a page boundary (avoiding a costly second TLB lookup), with speculative execution preparing the next virtual memory page whilst data is still being processed in the current loop. All of this is determined by the hardware, not the program itself. ARM SVE2 paper by N. Stevens
So, even if the performance of the vector unit is very high () there is a speedup less than , which suggests that the ratio f is crucial to the performance. This ratio depends on the efficiency of the compilation like adjacency of the elements in memory.
|
|